<template>
  <el-dialog :title="info.title" v-if="visible" :visible.sync="visible" append-to-body center width="460px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="100px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目名称" prop="pro_id">
            <ProSelect v-model="form.pro_id" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="表单类型" prop="type">
            <el-select v-model="form.type" size="small" style="width: 100%">
              <el-option
                v-for="item in types"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" :rows="4" v-model="form.remark" size="small" clearable  style="width: 100%" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleEdit()">保 存</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { formTypes, addForm, updForm } from '@/api/project'
import ProSelect from '@/components/ProSelect'
import form from '@/utils/form'

export default {
  components: { ProSelect },
  extends: form,
  props: {
    reqAdd: {
      default: addForm,
      type: Function
    },
    reqUpd: {
      default: updForm,
      type: Function
    }
  },
  data() {
    return {
      types: [],
      rules: {
        pro_id: [{ required: true, trigger: 'blur', message: '项目名称不可为空' }],
        type: [{ required: true, trigger: 'blur', message: '表单类型不可为空' }]
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form = this.info.edit
        this.formTypes()
      }
    }
  },
  mounted() {
  },
  methods: {
    formTypes() {
      formTypes({}).then(response => {
        this.types = response.list
      }).catch(err => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>

<style>
</style>
